package com.example.douyin.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.douyin.bean.DouYinSourceBean;
import com.example.douyin.service.DouYinSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.plaf.basic.BasicPopupMenuUI;
import java.util.List;

@RestController
@RequestMapping("/sugar")
public class DouYinSourceController {
    @Autowired
    public DouYinSourceService douYinSourceService;

    @GetMapping("/douYinSource")
    public JSONObject getDouYinSource() {
        List<DouYinSourceBean> getcharginganalysis = douYinSourceService.getDouYinSource();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONArray dataArray = new JSONArray();
        jsonObject.put("data", dataArray);
        for (DouYinSourceBean chargingAnalysisBean : getcharginganalysis) {
            JSONObject item = new JSONObject();
            item.put("name",chargingAnalysisBean.getSourceType());
            item.put("value",chargingAnalysisBean.getOrderRatio());
            dataArray.add(item);
        }
        return jsonObject;
    }
}
